var getCity = function(){
	jQuery('#city option').remove();
	jQuery('#country option').remove();
	jQuery.ajax({
		url:'/backend/city/show_city',
		type:'GET',
		data:{
				'id':jQuery("#province").find("option:selected").val()
		},
		dataType:'json',
		success:function(json){
			 var cityData = json.city_data;
		     if (cityData != null) {
		         for (var i = 0; i < cityData.length; i++) {
		             if (i == 0) {
		                 var option = document.createElement("option");
		                 jQuery("#city").append(option);
		                 option.value = i;
		                 option.text = "--请选择--";
		    
		              }
		              var option = document.createElement("option");
		              jQuery("#city").append(option);
		              option.value = cityData[i].id;
		              option.text = cityData[i].cityName;
		    
		           }
		     }
		}
		
	});
};

var getCountry = function(){
	jQuery('#country option').remove();
	jQuery.ajax({
		url:'/backend/city/show_city',
		type:'GET',
		data:{
				'id':jQuery("#city").find("option:selected").val()
		},
		dataType:'json',
		success:function(json){
			 var cityData = json.city_data;
		     if (cityData != null) {
		         for (var i = 0; i < cityData.length; i++) {
		             if (i == 0) {
		                 var option = document.createElement("option");
		                 jQuery("#country").append(option);
		                 option.value = i;
		                 option.text = "--请选择--";
		    
		              }
		              var option = document.createElement("option");
		              jQuery("#country").append(option);
		              option.value = cityData[i].id;
		              option.text = cityData[i].cityName;
		    
		           }
		     }
		}
		
	});
};

var errorCount=0;

function checkCompanyName(){
    var companyName = jQuery("#companyName").val();
    if(companyName==""||companyName.length==0){
        jQuery("#companyNameMsg").html("请输入公司名称");
        errorCount++;
    }else if(companyName.length>50){
        jQuery("#companyNameMsg").html("公司名称过长");
        errorCount++;
    }else{
        jQuery("#companyNameMsg").html("");
        errorCount=0;
    }

}    

var checkCompanyAddress = function(){
    var companyAddress = jQuery("#companyAddress").val();
    if(companyAddress==""||companyAddress.length==0){
        jQuery("#companyAddressMsg").html("请输入公司地址");
        errorCount++;
    }else if(companyAddress.length>200){
        jQuery("#companyAddressMsg").html("公司地址过长");
        errorCount++;
    }else{
        jQuery("#companyAddressMsg").html("");
        errorCount=0;
    }

}

var checkCompanyPhone = function(){
    var companyPhone = jQuery("#companyPhone").val();
    reg = /^((0\d{2,3})-)(\d{7,8})(-(\d{3,4}))?$/;
    if (companyPhone.length == 0) {
        jQuery("#companyPhoneMsg").html("请输入电话号码");
        errorCount++;
    }else if(!reg.test(companyPhone)){
        jQuery("#companyPhoneMsg").html("无效的电话号码");
        errorCount++;
    }else{
        jQuery("#companyPhoneMsg").html("");
        errorCount=0;
    }
}

var checkFarendaibiao = function(){
    var farendaibiao = jQuery("#farendaibiao").val();
    if(farendaibiao.length==0||farendaibiao==""){
        jQuery("#farendaibiaoMsg").html("请输入法人代表");
        errorCount++;
    }else if(farendaibiao.length>20){
        jQuery("#farendaibiaoMsg").html("法人代表过长");
        errorCount++;
    }else{
        jQuery("#farendaibiaoMsg").html("");
        errorCount=0;
    }

}
    
var checkContactPhone = function(){
    var contactPhone = jQuery("#contactPhone").val();
    reg = /^1[358]\d{9}$/;
    if (contactPhone.length == 0) {
        jQuery("#contactPhoneMsg").html("请输入手机号码");
        errorCount++;
    }else if (!reg.test(contactPhone)){
        jQuery("#contactPhoneMsg").html("无效的手机号码");
        errorCount++;
    } else {
        jQuery("#contactPhoneMsg").html("");
        errorCount=0;
    }
}

var checkEmail = function(){
    var contactEmail = jQuery("#contactEmail").val();
    reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/g;
    if(contactEmail.length==0||contactEmail==""){
        jQuery("#emailMsg").html("请输入email地址");
        errorCount++;
    }else if(!reg.test(contactEmail)){
        jQuery("#emailMsg").html("无效的email地址");
        errorCount++;
    }else{
        jQuery("#emailMsg").html("");
        errorCount=0;
    }
}

var checkYearMoney = function(){
    var yearMoney = jQuery("#yearMoney").val();
    if(yearMoney.length==0||yearMoney==""){
        jQuery("#yearMoneyMsg").html("请输入年销售额");
        errorCount++;
    }else if(isNaN(yearMoney)){
        jQuery("#yearMoneyMsg").html("必须输入数字");
        errorCount++;
    }else if(yearMoney.length>15){
        jQuery("#yearMoneyMsg").html("年销售额数值过大");
        errorCount++;
    }else{
        jQuery("#yearMoneyMsg").html("");
        errorCount=0;
    }
}

var checkDoEBusinessYears = function(){
    var doEBusinessYears = jQuery("#doEBusinessYears").val();
    if(doEBusinessYears.length==0||doEBusinessYears==""){
        jQuery("#doEBusinessYearsMsg").html("请输入从事电子商务年数");
        errorCount++;
    }else if(isNaN(doEBusinessYears)){
        jQuery("#doEBusinessYearsMsg").html("必须输入数字");
        errorCount++;
    }else if(doEBusinessYears.length>3){
        jQuery("#doEBusinessYearsMsg").html("从事电子商务年数过长");
        errorCount++;
    }else{
        jQuery("#doEBusinessYearsMsg").html("");
        errorCount=0;
    }
}

var checkWebUrl = function(){
    var webUrl = jQuery("#webUrl").val();
    if(webUrl.length==0||webUrl==""){
        jQuery("#webUrlMsg").html("请输入网店地址");
        errorCount++;
    }else if(webUrl.length>800){
        jQuery("#webUrlMsg").html("网店地址过长");
        errorCount++;
    }else{
        jQuery("#webUrlMsg").html("");
        errorCount=0;
    }
}

var checkTeamPerson = function(){
    var teamPerson = jQuery("#teamPerson").val();
    if(teamPerson.length==0||teamPerson==""){
        jQuery("#teamPersonMsg").html("请输入团队人数");
        errorCount++;
    }else if(isNaN(teamPerson)){
        jQuery("#teamPersonMsg").html("必须输入数字");
        errorCount++;
    }else if(teamPerson.length>15){
        jQuery("#teamPersonMsg").html("团队人数数值过大");
        errorCount++;
    }else{
        jQuery("#teamPersonMsg").html("");
        errorCount=0;
    }
}

var checkInventoryScale = function(){
    var inventoryScale = jQuery("#inventoryScale").val();
    if(inventoryScale.length==0||inventoryScale==""){
        jQuery("#inventoryScaleMsg").html("请输入库存规模");
        errorCount++;
    }else if(isNaN(inventoryScale)){
        jQuery("#inventoryScaleMsg").html("必须输入数字");
        errorCount++;
    }else if(inventoryScale.length>20){
        jQuery("#inventoryScaleMsg").html("库存规模数值过大");
        errorCount++;
    }else{
        jQuery("#inventoryScaleMsg").html("");
        errorCount=0;
    }
}

var checkAfterSalePerson = function(){
    var afterSalePerson = jQuery("#afterSalePerson").val();
    if(afterSalePerson.length==0||afterSalePerson==""){
        jQuery("#afterSalePersonMsg").html("请输入售后服务人数");
        errorCount++;
    }else if(isNaN(afterSalePerson)){
        jQuery("#afterSalePersonMsg").html("必须输入数字");
        errorCount++;
    }else if(afterSalePerson.length>20){
        jQuery("#afterSalePersonMsg").html("售后服务人数数值过大");
        errorCount++;
    }else{
        jQuery("#afterSalePersonMsg").html("");
        errorCount=0;
    }
}

var checkSendGoodsPerson = function(){
    var sendGoodsPerson = jQuery("#sendGoodsPerson").val();
    if(sendGoodsPerson.length==0||sendGoodsPerson==""){
        jQuery("#sendGoodsPersonMsg").html("请输入库房发货人数");
        errorCount++;
    }else if(isNaN(sendGoodsPerson)){
        jQuery("#sendGoodsPersonMsg").html("必须输入数字");
        errorCount++;
    }else if(sendGoodsPerson.length>20){
        jQuery("#sendGoodsPersonMsg").html("库房发货人数数值过大");
        errorCount++;
    }else{
        jQuery("#sendGoodsPersonMsg").html("");
        errorCount=0;
    }
}

var checkEntityShopNumbers = function(){
    var entityShopNumbers = jQuery("#entityShopNumbers").val();
    if(entityShopNumbers.length==0||entityShopNumbers==""){
        jQuery("#entityShopNumbersMsg").html("请输入实体店数");
        errorCount++;
    }else if(isNaN(entityShopNumbers)){
        jQuery("#entityShopNumbersMsg").html("必须输入数字");
        errorCount++;
    }else if(entityShopNumbers.length>20){
        jQuery("#entityShopNumbersMsg").html("实体店数值过大");
        errorCount++;
    }else{
        jQuery("#entityShopNumbersMsg").html("");
        errorCount=0;
    }
}

var checkLicenseNumber = function(){
    var licenseNumber = jQuery("#licenseNumber").val();
    if(licenseNumber.length==0||licenseNumber==""){
        jQuery("#licenseNumberMsg").html("请输入营业执照号码");
        errorCount++;
    }else if(licenseNumber.length>60){
        jQuery("#licenseNumberMsg").html("营业执照长度过大");
        errorCount++;
    }else{
        jQuery("#licenseNumberMsg").html("");
        errorCount=0;
    }
}

var checkDescription = function(){
    var description = jQuery("#description").val();
    if(description.length==0||description==""){
        jQuery("#descriptionMsg").html("请输入公司描述");
        errorCount++;
    }else if(description.length>1500){
        jQuery("#descriptionMsg").html("公司描述过长");
        errorCount++;
    }else{
        jQuery("#descriptionMsg").html("");
        errorCount=0;
    }
}

function checkAll()
{
    var companyName = jQuery("#companyName").val();
    var companyAddress = jQuery("#companyAddress").val();
    var companyPhone = jQuery("#companyPhone").val();
    var farendaibiao = jQuery("#farendaibiao").val();
    var contactPhone = jQuery("#contactPhone").val();
    var contactEmail = jQuery("#contactEmail").val();
    var yearMoney = jQuery("#yearMoney").val();
    var doEBusinessYears = jQuery("#doEBusinessYears").val();
    var webUrl = jQuery("#webUrl").val();
    var teamPerson = jQuery("#teamPerson").val();
    var inventoryScale = jQuery("#inventoryScale").val();
    var afterSalePerson = jQuery("#afterSalePerson").val();
    var sendGoodsPerson = jQuery("#sendGoodsPerson").val();
    var entityShopNumbers = jQuery("#entityShopNumbers").val();
    var licenseNumber = jQuery("#licenseNumber").val();
    var description = jQuery("#description").val();
    if(companyName.length==0||companyAddress.length==0||companyPhone.length==0||farendaibiao.length==0||
       contactPhone.length==0||contactEmail.length==0||yearMoney.length==0||doEBusinessYears.length==0||
       webUrl.length==0||teamPerson.length==0||inventoryScale.length==0||afterSalePerson.length==0||
       sendGoodsPerson.length==0||entityShopNumbers.length==0||licenseNumber.length==0||description.length==0){
        alert("数据不完全，请确认输入数据是否完整!!!")
        return false;
    }else{
        return true;
    }
}
